<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import lzccDriver from '@/api/lzcc/lzccDriver'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()

const options = reactive({
  id: 'flyos_lzcc_driver',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: lzccDriver.getList,
  add: {
    show: true,
    api: lzccDriver.save,
    auth: ['lzcc:driver:save']
  },
  edit: {
    show: true,
    api: lzccDriver.update,
    auth: ['lzcc:driver:update']
  },
  delete: {
    show: true,
    api: lzccDriver.deletes,
    auth: ['lzcc:driver:delete']
  },
  import: {
    show: true,
    url: 'lzcc/driver/import',
    templateUrl: 'lzcc/driver/downloadTemplate',
    auth: ['lzcc:driver:import']
  },
  export: {
    show: true,
    url: 'lzcc/driver/export',
    auth: ['lzcc:driver:export']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "绑定用户",
    dataIndex: "user_id",
    formType: "select",
    dict: {
      remote: 'system/user/remote',
      openPage: true,
      remoteOption: {
        select: ['nickname as label', 'id as value' ]
      },
    },
    hide: true,
  },
  {
    title: "司机姓名",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入司机姓名"
    }
  },
  {
    title: "运输公司",
    dataIndex: "company_id",
    formType: "select",
    search: true,
    dict: {
      remote: 'lzcc/transitCompany/remote',
      remoteOption: {
        select: ['name as label', 'id as value' ]
      },
      translation: true
    },
    commonRules: {
      required: true,
      message: "请输入运输公司"
    }
  },
  {
    title: "车型",
    dataIndex: "type_id",
    formType: "select",
    search: true,
    dict: {
      remote: 'lzcc/vehicle/remote',
      remoteOption: {
        select: ['name as label', 'id as value' ]
      },
      translation: true
    },
    commonRules: {
      required: true,
      message: "请输入车型"
    }
  },
  {
    title: "手机",
    dataIndex: "phone",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入手机"
    }
  },
  {
    title: "车牌号",
    dataIndex: "license_plate",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入车牌号"
    }
  },
  {
    title: "是否显示",
    dataIndex: "is_show",
    formType: "radio",
    search: true,
    sortable: {
      sortDirections: [
        "ascend",
        "descend"
      ],
      sorter: true
    },
    addDefaultValue: '1',
    dict: {
      name: "is_show",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    }
  },
  {
    title: "司机备注",
    dataIndex: "remark",
    formType: "textarea",
    hide: true
  },
  {
    title: "排序",
    dataIndex: "sort",
    formType: "input-number",
    sortable: {
      sortDirections: [
        "ascend",
        "descend"
      ],
      sorter: true
    },
    addDefaultValue: 100,
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入创建时间"
    },
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'lzcc:driver' } </script>